﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NerdDinner.Models
{

    public class DinnerRepository
    {
        private NerdDinnerDataContext db = new NerdDinnerDataContext();
        public IQueryable<Dinner> FindAllDinners()
        {
            return from dinner in db.Dinners
                       orderby dinner.DinnerID
                       select dinner;
        }
        public IQueryable<Dinner> FindUpcomingDinners()
        {  
            return from dinner in db.Dinners
                   where dinner.EventDate > DateTime.Now 
                   orderby dinner.EventDate
                   select dinner;
        }
        public Dinner FindDinner(int id)
        {
            return db.Dinners.Single(dinner => dinner.DinnerID == id);
        }
        public IQueryable<Dinner> FindExperidDinner()
        {
            return from dinner in db.Dinners
                   where dinner.EventDate < DateTime.Now
                   orderby dinner.EventDate
                   select dinner;
        }
        public void Add(Dinner dinner)
        {
            db.Dinners.InsertOnSubmit(dinner);
        }
        public void Delete(Dinner dinner)
        {
            db.Dinners.DeleteOnSubmit(dinner);
        }
        public void Save()
        {
            db.SubmitChanges();
        }
    }
}